import yaml
import json


def main(args):
    with open(args.src, 'r') as f:
        o = yaml.safe_load(f)

    if not args.save:
        s = json.dumps(o, indent=2)
        print(s)

    else:
        dst = args.src + '.json'
        with open(dst, 'w') as f:
            if args.save_pretty:
                json.dumps(o, f, indent=2)
            else:
                json.dump(o, f)

        with open(dst, 'r', encoding="utf-8") as f:
            s = f.read()
            print(s)


if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('src', type=str)
    parser.add_argument('--save', action='store_true')
    parser.add_argument('--save-pretty', action='store_true')
    args = parser.parse_args()
    main(args)
